https://leetcode.com/problems/rotate-array/
一個陣列將其向右旋轉k步,並回傳結果。
利用2個for迴圈,裡面那個迴圈負責移動紀錄則外面的負責移動次數。
void rotate(int* nums, int numsSize, int k) {
int tem;
for(int j=0;j<k;j++)
{
tem=nums[numsSize-1];
for(int i=numsSize-2;i>=0;i--)
nums[i+1]=nums[i];
nums[0]=tem;
}
}
var rotate = function(nums, k) {
for (var rounds = 0; rounds < k; rounds++) {
var last = nums[0];
for (var i = 0; i < nums.length - 1; i++) {
var tmp = nums[i + 1];
nums[i + 1] = last;
last = tmp;
}
nums[0] = last;
}
};
https://github.com/SIAOYUCHEN/leetcode
https://ithelp.ithome.com.tw/users/20100009/ironman/2500
https://ithelp.ithome.com.tw/users/20113393/ironman/2169
https://ithelp.ithome.com.tw/users/20107480/ironman/2435
https://ithelp.ithome.com.tw/users/20107195/ironman/2382
https://ithelp.ithome.com.tw/users/20119871/ironman/2210
https://ithelp.ithome.com.tw/users/20106426/ironman/2136
To think more about others advantage is the best choice for you to grow.
多去思考別人的好,才是讓自己成長的最好選擇。